package com.bupt.ilink.service.bailian.impl;

import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponse;
import com.aliyun.tea.TeaException;
import org.springframework.stereotype.Service;

import java.util.Map;
@Service
public class ApplyFileUploadLeaseService {

    /**
     * 返回格式
     *{
     *   "Status": "200",
     *   "RequestId": "D0379527-5B5D-5BBD-8790-CE9F63E10BA7",
     *   "Message": "",
     *   "Data": {
     *     "FileUploadLeaseId": "b6938be31023414f9a1a55abb70d55ee.1723206516743",
     *     "Type": "OSS.PreSignedUrl",
     *     "Param": {
     *       "Headers": {
     *         "X-bailian-extra": "MTQxODQ4MTM2NTIzODIwNA==",
     *         "Content-Type": ""
     *       },
     *       "Method": "PUT",
     *       "Url": "https://bailian-datahub-data-origin-prod.oss-cn-beijing.aliyuncs.com/1418481365238204/10249160/b6938be31023414f9a1a55abb70d55ee.1723206516743.txt?Expires=1723207116&OSSAccessKeyId=LTAI5tKzNnKPFwCJSCpxx51h&Signature=UT94HyWp%2BbZjqODAH3KUlrBxacs%3D"
     *     }
     *   },
     *   "Code": "Success",
     *   "Success": true
     * }
     **/
    public ApplyFileUploadLeaseResponse applyFileUploadLease(com.aliyun.bailian20231229.Client client, String CategoryId, String fileName, String fileLength, String md5, String WorkspaceId) throws Exception {
        com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = new com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest()
                .setFileName(fileName)
                .setMd5(md5) //TODO: 这个filePath怎么得到的问题
                .setSizeInBytes(fileLength);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.applyFileUploadLeaseWithOptions(CategoryId, WorkspaceId, applyFileUploadLeaseRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }
}
